package com.liu.dao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

/**
 * BaseDao:数据库操作工具类
 * @author Administrator
 *
 */
public class BaseDao {

	private static String driverClass="com.mysql.cj.jdbc.Driver";
	private static String url="jdbc:mysql://localhost:3306/interestring_shopdb?serverTimezone=UTC";
	private static String userName="root";
	private static String password="root";
	private Connection conn=null;

	//获得连接
	public Connection getConnection(){
		try {
			//1、加载驱动
			Class.forName(driverClass);
			//2、获得连接
			conn=DriverManager.getConnection(url,userName,password);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return conn;
	}

	//关闭连接
	public void closeAll(Connection conn,Statement st,ResultSet rs){
		try {
			if(conn!=null)
				conn.close();
			if(st!=null)
				st.close();
			if(rs!=null)
				rs.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
